/**
 * Copyright 2009 Takahiko Ito
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.unigram.oluolu.rqe.postprocessor;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.unigram.oluolu.common.FsUtil;
import org.unigram.oluolu.common.OluoluLogger;

/**
 * An implementation of IPostProcessor. This object just renames the input 
 * file into output file. 
 */
class PlainPostProcessor implements IPostProcessor {

    /** Logger. */
    private OluoluLogger logger = OluoluLogger.getLogger();

    /** Configuration. */
    private Configuration conf = null;
    
    /**
     * Default Constructor (never used).
     */
    private PlainPostProcessor() {}
    
    /**
     * Constructor.
     *  
     * @param jc configuration
     */
    public PlainPostProcessor(final Configuration jc) {
        this.conf = jc;
    }

    /**
     * Just copy input File into rqeFile.
     * 
     * @param inputFile - input file name
     * @param rqeFile - related query file
     * @param outputFile - output file name
     */
    public final void run(final String inputFile,
            final String rqeFile,
            final String outputFile) {

        FileSystem fs = null;
        try {
            fs = FileSystem.get(conf);
                    } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        logger.logInfo("start PlainPostProcessor");

        try {
            FsUtil.checkPath(new Path(outputFile), conf);
            fs.rename(new Path(rqeFile), new Path(outputFile));
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
